package com.coderc.library.view.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.coderc.library.R;
import com.github.chrisbanes.photoview.PhotoView;


/**
 * Created by vondear on 2016/7/19.
 * Mainly used for confirmation and cancel.
 */
public class RxDialogScaleView extends RxDialog {

    private PhotoView mPhotoView;

    private RelativeLayout mLayout;

    public RxDialogScaleView(Context context, int themeResId) {
        super(context, themeResId);
        initView();
    }

    public RxDialogScaleView(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView();
    }

    public RxDialogScaleView(Context context) {
        super(context);
        initView();
    }

    public RxDialogScaleView(Activity context) {
        super(context);
        initView();
    }

    public RxDialogScaleView(Context context, float alpha, int gravity) {
        super(context, alpha, gravity);
        initView();
    }

    public PhotoView getPhotoView() {
        return mPhotoView;
    }

    public void setImageUri(Uri uri) {
        mPhotoView.setImageURI(uri);
    }

    public void setImagesetImageResourceRes(int resId) {
        mPhotoView.setImageResource(resId);
    }

    public void setImageDrawable(Drawable drawable) {
        mPhotoView.setImageDrawable(drawable);
    }

    public void setBackground(int color){
        mLayout.setBackgroundColor(color);
    }

    private void initView() {
        View dialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_scaleview, null);
        mPhotoView = dialogView.findViewById(R.id.rx_scale_view);
        mLayout = dialogView.findViewById(R.id.lyt_root);
        ImageView ivClose = (ImageView) dialogView.findViewById(R.id.iv_close);
        ivClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                cancel();
            }
        });
        setFullScreen();
        setContentView(dialogView);
    }

}
